package com.cn.api.aop;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ValidateRequest implements HandlerInterceptor {

//	@Resource
//	RestaurantService restaurantService;

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3)
			throws Exception {
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3)
			throws Exception {
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
//		String token = request.getHeader("token");

		if (StringUtils.equalsIgnoreCase("OPTIONS", request.getMethod())) {
			return true;
		}

//		boolean checkParameter = StringUtil.checkParameter(token);
//		if (checkParameter) {
//			throw new ExceptionExpand(ErrorCode.CODE_LESS_PARAMETER, ErrorCode.MESSAGE_LESS_PARAMETER);
//		}
//		Integer restaurantId = restaurantService.getRestaurantIdByToken(token);
//
//		request.setAttribute("restaurantId", restaurantId);

		return true;
	}

}
